package com.ruoyi.staffDuty.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.staffDuty.domain.bo.MtStaffDutyFileShowBo;
import com.ruoyi.staffDuty.domain.vo.MtStaffDutyFileShowVo;
import com.ruoyi.staffDuty.service.IMtStaffDutyFileShowService;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文件查看情况
 *
 * @author ruoyi
 * @date 2023-11-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/staff/staffDutyFileShow")
public class MtStaffDutyFileShowController extends BaseController {

    private final IMtStaffDutyFileShowService iMtStaffDutyFileShowService;

    /**
     * 查询文件查看情况列表
     */
    //@SaCheckPermission("staff:staffDutyFileShow:list")
    @GetMapping("/list")
    public TableDataInfo<MtStaffDutyFileShowVo> list(MtStaffDutyFileShowBo bo, PageQuery pageQuery) {
        return iMtStaffDutyFileShowService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出文件查看情况列表
     */
    //@SaCheckPermission("staff:staffDutyFileShow:export")
    @Log(title = "文件查看情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MtStaffDutyFileShowBo bo, HttpServletResponse response) {
        List<MtStaffDutyFileShowVo> list = iMtStaffDutyFileShowService.queryList(bo);
        ExcelUtil.exportExcel(list, "文件查看情况", MtStaffDutyFileShowVo.class, response);
    }

    /**
     * 获取文件查看情况详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("staff:staffDutyFileShow:query")
    @GetMapping("/{id}")
    public R<MtStaffDutyFileShowVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iMtStaffDutyFileShowService.queryById(id));
    }

    /**
     * 新增文件查看情况
     */
    //@SaCheckPermission("staff:staffDutyFileShow:add")
    @Log(title = "文件查看情况", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MtStaffDutyFileShowBo bo) {
        return toAjax(iMtStaffDutyFileShowService.insertByBo(bo));
    }

    /**
     * 修改文件查看情况
     */
    //@SaCheckPermission("staff:staffDutyFileShow:edit")
    @Log(title = "文件查看情况", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MtStaffDutyFileShowBo bo) {
        return toAjax(iMtStaffDutyFileShowService.updateByBo(bo));
    }

    /**
     * 删除文件查看情况
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("staff:staffDutyFileShow:remove")
    @Log(title = "文件查看情况", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iMtStaffDutyFileShowService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
